#ARMGNU ?= aarch64-linux-gnu
board ?= rpi3

ifeq ($(board), rpi3)
COPS += -DCONFIG_BOARD_PI3B
QEMUI_FLAGS += -machine raspi3
else ifeq ($(board), rpi4)
COPS += -DCONFIG_BOARD_PI4B
endif

COPS += -g -Wall -nostdlib -nostdinc -Iinclude
ASMOPS = -g -Iinclude

BUILD_DIR = build
SRC_DIR = src

export OBJDIR := build/obj
export BINDIR := build/bin
export PROJECT_DIR = $(shell pwd)
export WORKDIR = /home/leon/share
export CONF_DIR = $(PROJECT_DIR)/config
export TOOLCHAIN_DIR = $(WORKDIR)/tools
export SRC_DIR:= $(PROJECT_DIR)/src
export IMAGE_PATH=$(TOOLCHAIN_DIR)/image/kernel.img
export BUILD_DIR:=$(PROJECT_DIR)/build

AllDirs := $(shell ls -R | grep '^\./.*:$' | awk '{gsub(":"," ");print}') .
Sources := $(foreach n,$(AllDirs) , $(wildcard $(n)/*.c))

INCLUDES := -I$(SDK_PATH)/includes  

Objs := $(patsubst %.c,%.o, $(Sources))
Deps := $(patsubst %.c,%.d, $(Sources))

#设置编译目录
BUILD_PATH:=$(TOP_DIR)/build
#设置编译临时目录
OBJ_PATH:=$(BUILD_PATH)/obj
#设置编译最终文件目录
BIN_PATH:=$(BUILD_PATH)/bin
#获取源文件目录下所有c文件列表
SRC:=$(foreach dir,$(SRC_PATH),$(wildcard $(dir)/*.c))
#去掉c文件目录
SRC_WITHOUT_DIR:=$(notdir $(SRC))
#生成.o文件列表
OBJ_WITHOUT_DIR:=$(patsubst %.c,%.o,$(SRC_WITHOUT_DIR))
#为.o文件列表加上编译目录
OBJ_WITH_BUILD_DIR:=$(addprefix $(OBJ_PATH)/,$(OBJ_WITHOUT_DIR))
$(info "OBJ_WITH_BUILD_DIR:$(OBJ_WITH_BUILD_DIR)")
#添加头文件目录
CFLAGS=$(addprefix -I,$(SRC_PATH))
#为gcc添加源文件搜索目录
VPATH=$(SRC_PATH)

#获取源文件路径下的所有.o文件名
GCC_SOURCE_PATH = $(foreach dir,$(SUBDIR),$(wildcard $(dir)/*.c))
GCC_OBJ_PATH = $(patsubst %.c,$(O_PATH)/%.o, $(notdir $(GCC_SOURCE_PATH)))

